@ibiz-template-plugin/ibiz-file-previewer 0.0.24 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1644,6 +1644,42 @@ var posix = {
1644
1644
  posix: null
1645
1645
  };
1646
1646
  posix.posix = posix;
1647
+ class EventEmitter {
1648
+ constructor() {
1649
+ __publicField(this, "handlers", {});
1650
+ }
1651
+ /**
1652
+ * 订阅事件
1653
+ * @param event 事件名
1654
+ * @param handler 处理函数
1655
+ * @returns 取消订阅函数
1656
+ */
1657
+ on(event, handler) {
1658
+ if (!this.handlers[event]) {
1659
+ this.handlers[event] = /* @__PURE__ */ new Set();
1660
+ }
1661
+ this.handlers[event].add(handler);
1662
+ return () => this.off(event, handler);
1663
+ }
1664
+ /**
1665
+ * 取消订阅事件
1666
+ * @param event 事件名
1667
+ * @param handler 处理函数
1668
+ */
1669
+ off(event, handler) {
1670
+ var _a;
1671
+ (_a = this.handlers[event]) == null ? void 0 : _a.delete(handler);
1672
+ }
1673
+ /**
1674
+ * 派发事件
1675
+ * @param event 事件名
1676
+ * @param payload 载荷
1677
+ */
1678
+ emit(event, payload) {
1679
+ var _a;
1680
+ (_a = this.handlers[event]) == null ? void 0 : _a.forEach((handler) => handler(payload));
1681
+ }
1682
+ }
1647
1683
  var f = 0;
1648
1684
  function u(e2, t2, n2, o2, i2, u2) {
1649
1685
  t2 || (t2 = {});
@@ -2253,7 +2289,7 @@ const FilePreviewImage = (props) => {
2253
2289
  onMouseDown: (evt) => controller.handleMouseDown(evt)
2254
2290
  }
2255
2291
  ),
2256
- /* @__PURE__ */ u(Teleport, { to: "#custom-controls", children: /* @__PURE__ */ u("div", { className: "image-toolbar-container", children: [
2292
+ /* @__PURE__ */ u(Teleport, { to: "#".concat(controller.controlsId), children: /* @__PURE__ */ u("div", { className: "image-toolbar-container", children: [
2257
2293
  /* @__PURE__ */ u(
2258
2294
  "button",
2259
2295
  {
@@ -16955,7 +16991,7 @@ const FilePreviewMD = (props) => {
16955
16991
  }, []);
16956
16992
  return /* @__PURE__ */ u("div", { className: "file-preview-md ".concat(c2.state.value.theme), children: [
16957
16993
  /* @__PURE__ */ u("div", { ref: previewRef }),
16958
- /* @__PURE__ */ u(Teleport, { to: "#custom-controls", children: /* @__PURE__ */ u("button", { title: "目录", className: "control-btn", onClick: onOutline, children: /* @__PURE__ */ u("span", { className: "icon", children: /* @__PURE__ */ u(ThumbnailSvg, {}) }) }) })
16994
+ /* @__PURE__ */ u(Teleport, { to: "#".concat(c2.controlsId), children: /* @__PURE__ */ u("button", { title: "目录", className: "control-btn", onClick: onOutline, children: /* @__PURE__ */ u("span", { className: "icon", children: /* @__PURE__ */ u(ThumbnailSvg, {}) }) }) })
16959
16995
  ] });
16960
16996
  };
16961
16997
  function deepFreeze(obj) {
@@ -19214,6 +19250,14 @@ const FilePreviewImageGroup = (props) => {
19214
19250
  observer.disconnect();
19215
19251
  };
19216
19252
  }, []);
19253
+ y$1(() => {
19254
+ const unsubscribe = controller.events.on("goToPage", (page) => {
19255
+ scrollToPage(page);
19256
+ });
19257
+ return () => {
19258
+ unsubscribe();
19259
+ };
19260
+ }, []);
19217
19261
  return /* @__PURE__ */ u("div", { className: "file-preview-image-group", children: [
19218
19262
  /* @__PURE__ */ u(
19219
19263
  "div",
@@ -19276,7 +19320,7 @@ const FilePreviewImageGroup = (props) => {
19276
19320
  ]
19277
19321
  }
19278
19322
  ),
19279
- /* @__PURE__ */ u(Teleport, { to: "#custom-controls", children: /* @__PURE__ */ u("div", { className: "image-toolbar-container", children: [
19323
+ /* @__PURE__ */ u(Teleport, { to: "#".concat(controller.controlsId), children: /* @__PURE__ */ u("div", { className: "image-toolbar-container", children: [
19280
19324
  /* @__PURE__ */ u(
19281
19325
  "button",
19282
19326
  {
@@ -19497,7 +19541,7 @@ const FilePreviewShell = (props) => {
19497
19541
  ] })
19498
19542
  ] }),
19499
19543
  /* @__PURE__ */ u("div", { className: "preview-controls", children: [
19500
- /* @__PURE__ */ u("div", { className: "custom-controls", id: "custom-controls" }),
19544
+ /* @__PURE__ */ u("div", { className: "custom-controls", id: controller.controlsId }),
19501
19545
  /* @__PURE__ */ u(
19502
19546
  "button",
19503
19547
  {
@@ -19541,7 +19585,9 @@ const FilePreviewShell = (props) => {
19541
19585
  children: state.value.isCreated && controller.preViewComp && controller.preViewController ? _$2(controller.preViewComp, {
19542
19586
  controller: controller.preViewController,
19543
19587
  onInitialization: () => {
19588
+ var _a, _b;
19544
19589
  controller.updateState({ isLoading: false });
19590
+ (_b = (_a = controller.getOptions()).onInitialized) == null ? void 0 : _b.call(_a);
19545
19591
  }
19546
19592
  }) : null
19547
19593
  }
@@ -19560,9 +19606,19 @@ class FilePreviewItemController {
19560
19606
  * 状态
19561
19607
  */
19562
19608
  __publicField(this, "state", d$1({}));
19609
+ /**
19610
+ * 事件对象,用于向组件派发瞬时动作事件
19611
+ */
19612
+ __publicField(this, "events", new EventEmitter());
19563
19613
  this.filePreviewShell = filePreviewShell;
19564
19614
  this.initState();
19565
19615
  }
19616
+ /**
19617
+ * 工具栏容器唯一 id(代理自 shell controller)
19618
+ */
19619
+ get controlsId() {
19620
+ return this.filePreviewShell.controlsId;
19621
+ }
19566
19622
  /**
19567
19623
  * 更新状态
19568
19624
  * - 所有的状态更新必须调用该方法,以便界面响应
@@ -19741,6 +19797,22 @@ class FilePreviewImageGroupController extends FilePreviewImageController {
19741
19797
  const { showThumbnailPanel } = this.state.value;
19742
19798
  this.updateState({ showThumbnailPanel: !showThumbnailPanel });
19743
19799
  }
19800
+ /**
19801
+ * 跳转至指定页(0-based)
19802
+ * - 越界或内容未加载时静默忽略
19803
+ * - 同步更新 currentPage,并派发 goToPage 事件由组件执行滚动
19804
+ * @param page 目标页索引
19805
+ */
19806
+ goToPage(page) {
19807
+ setTimeout(() => {
19808
+ const { total } = this.state.value;
19809
+ if (!Number.isInteger(page) || total <= 0 || page < 0 || page >= total) {
19810
+ return;
19811
+ }
19812
+ this.updateState({ currentPage: page });
19813
+ this.events.emit("goToPage", page);
19814
+ }, 0);
19815
+ }
19744
19816
  /**
19745
19817
  * 处理旋转角度改变
19746
19818
  * @param value
@@ -20650,6 +20722,7 @@ class FilePreviewItemDispatcher {
20650
20722
  * 引擎预览组件映射表
20651
20723
  */
20652
20724
  __publicField(FilePreviewItemDispatcher, "enginePreviewMap", /* @__PURE__ */ new Map());
20725
+ let filePreviewInstanceId = 0;
20653
20726
  class FilePreviewShellController {
20654
20727
  /**
20655
20728
  * 构造函数
@@ -20668,6 +20741,11 @@ class FilePreviewShellController {
20668
20741
  * 文件预览控制器
20669
20742
  */
20670
20743
  __publicField(this, "preViewController");
20744
+ /**
20745
+ * 当前实例工具栏容器唯一 id(不带 #)
20746
+ * - 构造时确定,生命周期内不变
20747
+ */
20748
+ __publicField(this, "controlsId");
20671
20749
  /**
20672
20750
  * 文件预览器状态对象
20673
20751
  */
@@ -20689,6 +20767,8 @@ class FilePreviewShellController {
20689
20767
  if (options.theme) this.updateState({ theme: options.theme });
20690
20768
  FilePreviewItemDispatcher.initialize();
20691
20769
  this.getState = this.getState.bind(this);
20770
+ filePreviewInstanceId += 1;
20771
+ this.controlsId = "custom-controls-".concat(filePreviewInstanceId);
20692
20772
  }
20693
20773
  /**
20694
20774
  * 更新状态
@@ -20874,6 +20954,17 @@ class FilePreviewShellController {
20874
20954
  this.mountComponent();
20875
20955
  this.updateState({ isCreated: true });
20876
20956
  }
20957
+ /**
20958
+ * 跳转至目标页
20959
+ * - 仅对图片组场景生效,其它场景忽略
20960
+ * - 页码为 0-based
20961
+ * @param page 目标页索引
20962
+ */
20963
+ goToPage(page) {
20964
+ if (this.preViewController instanceof FilePreviewImageGroupController) {
20965
+ this.preViewController.goToPage(page);
20966
+ }
20967
+ }
20877
20968
  }
20878
20969
  export {
20879
20970
  ActionType,